<template>
  <div class="topCard">
    <div v-for="(item, index) in cardData" :key="index" class="topCard_item">
      <div class="topCard_item_top">
        <div class="topCard_item_top_icon">
          <img v-if="index === 0" src="../../../assets/statistics/received.png" alt="">
          <img v-if="index === 1" src="../../../assets/statistics/obligation.png" alt="">
          <img v-if="index === 2" src="../../../assets/statistics/invoiced.png" alt="">
          <img v-if="index === 3" src="../../../assets/statistics/notInvoiced.png" alt="">
        </div>

        <div class="topCard_item_top_title">
          <span>{{ index === 0 ? '已付款' : index === 1 ? '未付款' : index === 2 ? '已开票' : '未开票' }}</span>（元）
        </div>

        <div class="topCard_item_top_date">{{ item.date }}</div>
      </div>

      <div class="topCard_item_bottom">
        <div class="topCard_item_bottom_number">{{ item.money }}</div>

        <div v-if="item.trend === '0'" class="topCard_item_bottom_right down">
          {{ item.change }}<img src="../../../assets/statistics/md-trending_down.png" alt="">
        </div>
        <div v-if="item.trend === '1'" class="topCard_item_bottom_right up">
          {{ item.change }}<img src="../../../assets/statistics/md-trending_up.png" alt="">
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getCardData } from '@/api/chart.js'
export default {
  data() {
    return {
      cardData: [],
      selectYear: '',
      selectQuarter: '',
      selectMonth: ''

    }
  },
  created() {
    this.getCardData()
  },
  methods: {
    // 获取卡片数据
    async getCardData() {
      const res = await getCardData({
        selectYear: this.selectYear,
        selectQuarter: this.selectQuarter,
        selectMonth: this.selectMonth
      })
      // console.log('卡片数据', res)
      if (res.code === 200) {
        this.cardData = res.data
      }
    },

    // 筛选
    selectChange(data) {
      this.selectYear = data.year
      this.selectQuarter = data.quarter
      this.selectMonth = data.month
      this.getCardData()
    }
  }
}
</script>

<style lang="scss" scoped>
.topCard {
  display: flex;
  flex-wrap: wrap;

  &_item {
    flex: 1;
    min-width: 300px;
    padding: 30px;
    background-color: #fff;
    margin-right: 20px;
    margin-bottom: 20px;
    border-radius: 6px;

    &_top {
      display: flex;
      align-items: center;
      font-size: 14px;
      color: #8492A6;

      &_icon {
        width: 44px;
        height: 44px;
        background-color: rgba($color: #8492A6, $alpha: .1);
        margin-right: 20px;
        border-radius: 6px;
        display: flex;
        justify-content: center;
        align-items: center;

        img {
          width: 24px;
          height: 24px;
        }
      }

      &_title {
        margin-right: auto;

        span {
          color: #000000;
          font-weight: 500;
        }

      }
    }

    &_bottom {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 30px;

      &_number {
        font-size: 28px;
        color: #101010;
        font-weight: 600;
      }

      &_right {
        font-size: 14px;
        padding: 5px 10px;
        border-radius: 4px;
        display: flex;
        align-items: center;

        &.up {
          color: #F44C4C;
          background-color: rgba($color: #F44C4C, $alpha: .1);
        }

        &.down {
          color: #2CAB40;
          background-color: rgba($color: #2CAB40, $alpha: .1);
        }

        span {
          margin: 0 5px;
        }

        img {
          width: 14px;
          height: 14px;
          margin-left: 5px;
        }
      }
    }
  }
}
</style>
